<script>
	import UserApi from "@/api/user"
	import {
		mapMutations
	} from 'vuex';
	export default {
		onLaunch: function() {
			console.log('App Launch')
			this.doLogin()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			...mapMutations(['login', 'stat']),
			doLogin() {
				let code = this.getQueryVariable('code')
				if (code) {
					UserApi.login({
						code: code
					}).then((res) => {
						this.login(res);
						this.getStat();
					})
				}
			},
			getStat() {
				UserApi.stat().then((res) => {
					this.stat(res)
				})
			},
			getQueryVariable(variable) {
				var query = window.location.search.substring(1);
				var vars = query.split("&");
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split("=");
					if (pair[0] == variable) {
						return pair[1];
					}
				}
				return (false);
			}
		}
	}
</script>

<style>
	@import "colorui/main.css";
	@import "colorui/icon.css";

	.gap-2 {
		gap: 30upx;
	}

	.grid-cols-2 {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.grid-d {
		display: grid;
	}

	.foot-h {
		height: 120upx;
	}

	.foot-but {
		position: fixed;
		width: 100%;
		bottom: 0;
		z-index: 1024;
		padding: 20upx;
		background-color: #ffffff;
	}

	.foot-but-h {
		height: 120upx;
	}

	.h-screen {
		height: 100vh;
	}
</style>
